package com.app.qbake.module.mine.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.wind.base.BaseActivity;
import com.wind.base.utils.ActivityUtil;
import com.wind.base.utils.Navigator;
import com.wind.data.mine.bean.Address;
import com.app.qbake.R;
import com.app.qbake.module.mine.EditAddressFragment;
import com.app.qbake.module.mine.event.EditAddressSuccessEvent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

public class EditAddressActivity extends BaseActivity {
    public static void start(Context context){
        start(context,null);
    }
    public static void start(Context context, Address address){
        Navigator.navigate(context,EditAddressActivity.class,address);
    }

    private EditAddressFragment f;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_container_with_toolbar);
        Address address=Navigator.getSerializableExtra(this);
        replaceFragment(f= EditAddressFragment.getInstance(address));

        EventBus.getDefault().register(this);
    }

    @Override
    protected void setTitle() {
        mTitleBar.setTitle("设置地址");
        mTitleBar.setRightText("保存");
        mTitleBar.setRightClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                f.update();
            }
        });
    }

    @Subscribe
    public void onEditAddressSuccessEvent(EditAddressSuccessEvent event){
        ActivityUtil.finish(this);
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
